<template>
  <div class="container">
    <App-header>
      <span slot="title">快点点</span>
      <span @click="login" slot="login">登录</span>
      <span slot="line">|</span>
      <span @click="register" slot="register">注册</span>
    </App-header>
    <div class="currCity">
      <div class="currCity__item">
        当前定位城市：
        <span>定位不准时，请在城市列表中选择</span>
      </div>
    </div>
    <div class="locationCity">
      <router-link class="router_link" :to="{ name: 'CityCopy', query: { cityName: this.locationCity } }">
        <div class="locationCity__item"><span>{{locationCity}}</span>
          <img src="../assets/下一步.png" alt="">
        </div>
      </router-link>
    </div>
    <div class="hotCity">
      <p>热门城市</p>
    </div>
      <div class="hotAllCity">
        <div class="hotAllCity-item" v-for="(item, index) in hotCityList" :key="index">
          <router-link class="router_link"  :to="{ name: 'CityCopy', query: { city: item.id, cityName: item.name } }">
            {{item.name}}
          </router-link>
        </div>
      </div>
    <div class="allCity" v-for="(item, index) in allCityList" :key="index">
      <div class="allCityTitle">
        <p>{{item}}&nbsp;&nbsp;&nbsp;<span>{{sortTitle[index]}}</span></p>
      </div>
      <div class="allCityList">
        <div class="allCityList-item" v-for="(item, index) in city[item]" :key="index">
          <router-link class="router_link"  :to="{ name: 'CityCopy', query: { city: item.id, cityName: item.name } }">
            {{item.name}}
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import AppHeader from './AppHeader.vue'
export default {
  name: 'Home',
  data () {
    return {
      locationCity: [],
      hotCityList: [],
      city: '',
      allCityList: [],
      sortTitle: ['(按字母排序)']
    }
  },
  methods: {
    login () {
      this.$router.push({ name: 'Login' })
    },
    register () {
      this.$router.push({ name: 'Register' })
    },
    locCity () {
      this.$http.locationCityList({
        type: 'guess'
      }).then(res => {
        this.locationCity = res.data.name
        window.console.log(res.data.name)
      }).catch(err => {
        window.console.log(err)
      })
    },
    hotCity () {
      this.$http.locationCityList({
        type: 'hot'
      }).then(res => {
        this.hotCityList = res.data
        window.console.log(res.data)
      }).catch(err => {
        window.console.log(err)
      })
    },
    allCity () {
      this.$http.locationCityList({
        type: 'group'
      }).then(res => {
        this.city = res.data
        Object.keys(res.data).forEach((item) => {
          this.allCityList.push(item)
        })
        this.allCityList.sort()
      }).catch(err => {
        window.console.log(err)
      })
    }
  },
  components: { AppHeader },
  created () {
    window.console.log(this.hotCityList)
    this.locCity()
    this.hotCity()
    this.allCity()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  *{
    margin: 0px;
    padding: 0px;
    text-decoration: none;
  }
  .container{
    width: 750px;
    height: 100%;
    background-color: #f5f5f5;
    .currCity{
      width: 100%;
      .currCity__item{
        width: 95%;
        height: 86px;
        margin: 0px auto;
        color: #6b6b6b;
        font-size: 25px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        span{
          color: #9f9f9f;
        }
      }
    }
    .locationCity{
      width: 100%;
      height: 80px;
      background-color: #fff;
      border-top: 4px solid #e4e4e4;
      border-bottom: 4px solid #e4e4e4;
      .router_link{
        color: #65a9ee;
      }
      .locationCity__item{
        width: 95%;
        margin: 0px auto;
        height: 80px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        span{
          color: #65a9ee;
          font-size: 33px;
        }
        img{
          width: 30px;
        }
      }
    }
    .hotCity{
      width: 100%;
      height: 66px;
      display: flex;
      background-color: #fff;
      align-items: center;
      margin-top: 20px;
      border-top: 4px solid #e4e4e4;
      border-bottom: 1px solid #e4e4e4;
      p{
        width: 95%;
        margin: 0px auto;
        color: #6b6b6b;
        font-size: 25px;
      }
    }
    .hotAllCity{
      width: 100%;
      height: 165px;
      background-color: #fff;
      .hotAllCity-item{
        width: 183.5px;
        height: 80px;
        float: left;
        text-align: center;
        line-height: 80px;
        color: #65a9ee;
        font-size: 33px;
        border: 1px solid #e4e4e4;
        .router_link{
          color: #65a9ee;
        }
      }
    }
    .allCity{
      width: 100%;
      .allCityTitle{
        width: 100%;
        height: 66px;
        display: flex;
        background-color: #fff;
        align-items: center;
        margin-top: 20px;
        border-top: 4px solid #e4e4e4;
        border-bottom: 1px solid #e4e4e4;
        p{
          width: 95%;
          margin: 0px auto;
          color: #6b6b6b;
          font-size: 26px;
          span{
            color: #9f9f9f;
          }
        }
      }
      .allCityList{
        width: 100%;
        .allCityList-item{
          width: 183.5px;
          height: 80px;
          line-height: 80px;
          background-color: #fff;
          float: left;
          overflow: hidden;
          font-size: 27px;
          border: 1px solid #e4e4e4;
          text-align: center;
          .router_link{
            color: #666;
          }
        }
      }
    }
  }
</style>
